from appium import webdriver
from appium.options.android import UiAutomator2Options


from tests.api_demo.pages.base_page import BasePage


class Api(BasePage):
    def start_api(self):
        caps = {
            # 设置 app 安装的平台（Android、iOS）
            "platformName": "android",
            # 设置 appium 驱动
            "appium:automationName": "uiautomator2",
            # 设置设备名称
            "appium:deviceName": "emulator-5554",
            # 设置 app 的包名
            "appium:appPackage": "io.appium.android.apis",
            # 设置 app 启动页
            "appium:appActivity": ".ApiDemos",
            # 执行完成之后是否停止app
            "appium:shouldTerminateApp": True,
            # 启动driver的时候是否强制启动app
            "appium:forceAppLaunch": True,
            # 不重置app
            "appium:noReset": True
        }
        self.driver = webdriver.Remote("http://127.0.0.1:4723", options=UiAutomator2Options().load_capabilities(caps))
        self.set_implicitly_wait(self.DEFAULT_IMPLICITLY)
        return self


    def quit_api(self):
        self.driver.quit()

    def goto_mainpage(self):
        from tests.api_demo.pages.api_page.main_page import MainPage
        return MainPage(self.driver)

